package com.disruptor.sample._08complex02.consumer;

import com.disruptor.sample._08complex02.dto.Order;
import com.lmax.disruptor.WorkHandler;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Consumer implements WorkHandler<Order> {

  private String consumerId;

  private static AtomicInteger count = new AtomicInteger(0);

  public Consumer(String consumerId) {
    this.consumerId = consumerId;
  }

  @Override
  public void onEvent(Order order) throws Exception {
    int cnt = count.incrementAndGet();
    log.info("当前消费者: {}，消费信息：{}，count：{}", this.consumerId, order.getId(), cnt);
  }

  public int getCount() {
    return count.get();
  }

}
